package com.contact.util.util.search;

import java.util.List;

/**
 * Returns sublists of items page by page 
 * 
 * @author dimitri
 *
 * @param <T>
 */
public class ListDataProcessorSource<T> implements DataProcessorSource<T> {

	private final List<T> list;

	public ListDataProcessorSource(List<T> list) {
		super();
		this.list = list;
	}
	
	@Override
    public List<T> getData(IPaginationInfo paginationInfo) {
        int start = paginationInfo.getFirstRow();
        int end = start + Math.min(list.size() - start, paginationInfo.getMaxResults());
        return list.subList(start, end);
    }

}
